package com.sgb.kjwl.push;

import android.app.Notification;
import android.content.Context;
import android.content.Intent;

import com.sgb.kjwl.R;
import com.sgb.kjwl.view.ui.activity.MainActivity;
import com.swgk.core.util.MLog;

import cn.jpush.android.api.BasicPushNotificationBuilder;
import cn.jpush.android.api.CmdMessage;
import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.JPushMessage;
import cn.jpush.android.api.NotificationMessage;
import cn.jpush.android.service.JPushMessageReceiver;

/**
 * 自定义JPush message 接收器,包括操作tag/alias的结果返回(仅仅包含tag/alias新接口部分)
 */
public class PushReceiver extends JPushMessageReceiver {

    @Override
    public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
        MLog.i("test1", jPushMessage.toString());

    }

    @Override
    public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage) {
        MLog.i("test2", jPushMessage.toString());

    }

    @Override
    public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
        MLog.i("test3", jPushMessage.toString());

    }

    @Override
    public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
        MLog.i("test4", jPushMessage.toString());

    }

    @Override
    public void onMessage(Context context, CustomMessage customMessage) {
        MLog.i("test5", customMessage.toString());
    }

    @Override
    public void onNotifyMessageArrived(Context context, NotificationMessage notificationMessage) {
        MLog.i("test6", notificationMessage.toString());
    }

    @Override
    public void onNotifyMessageOpened(Context context, NotificationMessage notificationMessage) {
        Intent i = new Intent(context, MainActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(i);
    }

    @Override
    public void onRegister(Context context, String s) {
        MLog.i("test7", s);
        setStyleBasic(context);
    }

    @Override
    public void onCommandResult(Context context, CmdMessage cmdMessage) {
        MLog.i("test8", cmdMessage.toString());
    }

    private void setStyleBasic(Context context) {
        BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(context);
        builder.statusBarDrawable = R.drawable.jpush_notification_icon;
        builder.notificationFlags = Notification.FLAG_AUTO_CANCEL;
        builder.notificationDefaults = Notification.DEFAULT_SOUND;
        JPushInterface.setPushNotificationBuilder(1, builder);
    }
}
